package com.estasenposse.tdam.services;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;

public class AlarmUpdateReceiver extends WakefulBroadcastReceiver {
	

	@Override
	public void onReceive(Context context, Intent intent) {
		Log.i("Alarm Wakeful", "andando");
			Intent service = new Intent(context, OnHandlerIntent.class);
			startWakefulService(context, service);
		
	}

	public void setAlarm(Context context) {
		// Setting de alarm!!!
		AlarmManager am = (AlarmManager) context
				.getSystemService(Context.ALARM_SERVICE);
		Intent i = new Intent(context, AlarmUpdateReceiver.class);
		PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
		am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
				1000 * 60 * 60 * 2, pi);
		// Final: 1000 * 60 * 60 * horas
	}

	public void CancelAlarm(Context context) {
		Intent intent = new Intent(context, AlarmUpdateReceiver.class);
		PendingIntent sender = PendingIntent
				.getBroadcast(context, 0, intent, 0);
		AlarmManager alarmManager = (AlarmManager) context
				.getSystemService(Context.ALARM_SERVICE);
		alarmManager.cancel(sender);
	}

}
